package com.example.tyz1201.myaccount.Activity.Activity.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.tyz1201.myaccount.Activity.Activity.Adapter.ChoosedStyleAdapter;
import com.example.tyz1201.myaccount.Activity.Activity.Model.ChooseStyleModel;
import com.example.tyz1201.myaccount.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tyz1201 on 2016/4/8.
 */
public class ChooesedStyleActivity extends AppCompatActivity {
    Toolbar toolbar_choose_style;
    ListView lv_choose_style;
    ChoosedStyleAdapter choosedStyleAdapter;
    List<ChooseStyleModel> styleMessages = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choosedstyle);

        toolbar_choose_style = (Toolbar) findViewById(R.id.toolbar_choose_style);
        lv_choose_style = (ListView) findViewById(R.id.lv_choose_style);

        toolbar_choose_style.setTitle("选择类型");
        toolbar_choose_style.setTitleTextColor(getResources().getColor(R.color.Black));
        setSupportActionBar(toolbar_choose_style);

        initstyleMessages();

        choosedStyleAdapter = new ChoosedStyleAdapter(styleMessages, ChooesedStyleActivity.this);
        lv_choose_style.setAdapter(choosedStyleAdapter);

        lv_choose_style.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                String iconName = styleMessages.get(position).getChooseStyleName();
                int iconId = styleMessages.get(position).getChooseStyleId();

                Intent data = new Intent();

                data.putExtra("iconId", iconId);
                Log.d("iconId",""+iconId);
                data.putExtra("iconName", iconName);
                Log.d("iconName",iconName);
                setResult(RESULT_OK, data);
                finish();
            }
        });


    }

    private void initstyleMessages() {

        ChooseStyleModel breakfast = new ChooseStyleModel(R.mipmap.drink, "早餐");
        ChooseStyleModel lunch = new ChooseStyleModel(R.mipmap.inbox, "午餐");
        ChooseStyleModel dinner = new ChooseStyleModel(R.mipmap.photos, "晚餐");
        ChooseStyleModel others = new ChooseStyleModel(R.mipmap.coin_yen, "其他");

        styleMessages.add(breakfast);
        styleMessages.add(lunch);
        styleMessages.add(dinner);
        styleMessages.add(others);

    }

}
